package com.cn.download.servlet;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

public class DownloadServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType(getServletContext().getMimeType("xxx.itcast"));
		response.setHeader("content-disposition", "attachment;filename=aaa.itcast");
		InputStream is = getServletContext().getResourceAsStream("/download/08-BookeStor.itcast");
		ServletOutputStream os = response.getOutputStream();
		IOUtils.copy(is, os);
		is.close();
		os.close();
	}

}

//response.setHeader("content-disposition", "attachment;filename=a.mp3");